package com.svnservices.hannibal.dao;

import com.svnservices.domaininterface.SvnMessage;
import com.svnservices.hannibal.activerecord.SvnMessageAR;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; 
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

import hannibal.dao.db.spring.Dao;

import java.sql.ResultSet;
import java.sql.SQLException;

@javax.annotation.Generated
(
	value="hannibal.generator.Generator",
	comments="",
	date = ""
)
   
public class SvnMessageDao
	extends Dao
{
	protected SvnMessageDao(javax.sql.DataSource _dataSource)
	{
		super(_dataSource);
	}

	protected ParameterizedRowMapper<SvnMessageAR> mapper = new ParameterizedRowMapper<SvnMessageAR>()
	{
		public SvnMessageAR mapRow(ResultSet _resultSet, int _rowNum)
				throws SQLException
		{
			SvnMessageAR svnMessage = new SvnMessageAR();

			svnMessage.setId(hannibal.util.DatabaseUtil.getString(_resultSet, "id"));
			svnMessage.setName(hannibal.util.DatabaseUtil.getString(_resultSet, "name"));
			svnMessage.setMessage(hannibal.util.DatabaseUtil.getString(_resultSet, "message"));
			svnMessage.setCategory(hannibal.util.DatabaseUtil.getString(_resultSet, "category"));
			
			return svnMessage;
		}
	};

	public java.util.Collection<SvnMessageAR> collect(int _offset, int _limit, String _orderBy)
	{
		String sql = "SELECT id AS id, name AS name, message AS message, category AS category FROM SvnMessage ORDER BY :orderBy LIMIT ? OFFSET ?";
		sql = sql.replaceAll(":orderBy", _orderBy);

		return query(sql, this.mapper, _limit, _offset);
	}

	public int insert(SvnMessageAR _svnMessage)
	{
		final String sql = "INSERT INTO SvnMessage ( id, name, message, category) VALUES ( ?, ?, ?, ?)";
		
		return update(sql, _svnMessage.getId(), _svnMessage.getName(), _svnMessage.getMessage(), _svnMessage.getCategory());
	}


	public SvnMessage get(final java.lang.String _id)
	{
		final String sql = "SELECT id AS id, name AS name, message AS message, category AS category FROM SvnMessage WHERE id = ?";

		return queryForObject(sql, this.mapper, _id);
	}

	public SvnMessage get(SvnMessageAR _svnMessage)
	{
		return get(_svnMessage.getId());
	}

	public int update(SvnMessageAR _svnMessage)
	{
		final String sql = "UPDATE SvnMessage SET name = ?, message = ?, category = ? WHERE id = ?";

		return update(sql, _svnMessage.getName(), _svnMessage.getMessage(), _svnMessage.getCategory(), _svnMessage.getId() );
	}

	public int del(final java.lang.String _id)
	{
		return delete(_id);
	}

	public int delete(final java.lang.String _id)
	{
		final String sql = "DELETE FROM SvnMessage WHERE id = ?";

		return update(sql, _id);
	}

	public int del(SvnMessageAR _svnMessage)
	{
		return delete(_svnMessage);
	}

	public int delete(SvnMessageAR _svnMessage)
	{
		return delete(_svnMessage.getId());
	}


}